package logic

import (
	"context"

	"go-zero-mall/app/admin/cmd/rpc/internal/svc"
	"go-zero-mall/app/admin/cmd/rpc/pd"

	"github.com/zeromicro/go-zero/core/logx"
)

type MenuUpdateHiddenLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewMenuUpdateHiddenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MenuUpdateHiddenLogic {
	return &MenuUpdateHiddenLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 菜单-更新显示状态
func (l *MenuUpdateHiddenLogic) MenuUpdateHidden(in *pd.UmsMenuStatusReq) (*pd.Response, error) {
	d, err := l.svcCtx.UmsMenuModel.FindOne(l.ctx, in.Id)
	if err != nil {
		return nil, err
	}
	switch d.Hidden {
	case 0:
		d.Hidden = 1
	case 1:
		d.Hidden = 0
	}

	err = l.svcCtx.UmsMenuModel.Update(l.ctx, d)
	if err != nil {
		return nil, err
	}

	return &pd.Response{Result: 1}, nil
}
